package com.power.sifa.net.controller;

import com.plf.common.domain.ResponseDTO;
import com.power.sifa.net.api.IGeneral_treeFeign;
import com.power.sifa.net.model.General_tree;
import com.power.sifa.net.model.General_tree_option;
import com.power.sifa.net.service.General_treeService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "General_treeController",tags={"通用树组件接口"})
@Slf4j
public class General_treeController implements IGeneral_treeFeign {

    @Resource
    private General_treeService general_treeService;

    @Override
    public ResponseDTO addBuild(String applyid, String cornumber, List<General_tree> treeBuild) {
        try {
            return ResponseDTO.succData(this.general_treeService.addBuild(applyid, cornumber, treeBuild));
        } catch (Exception e) {
            e.printStackTrace();
            log.info("/generalTree/addBuild 新增构建树失败 msg[{}]", e.getMessage());
            return ResponseDTO.wrap(500, "/generalTree/addBuild 新增构建树失败");
        }
    }

    @Override
    public ResponseDTO editBuild(String applyid, List<General_tree> treeBuild) {
        try {
            return ResponseDTO.succData(this.general_treeService.editBuild(applyid, treeBuild));
        } catch (Exception e) {
            log.info("/generalTree/editBuild 编辑构建树失败 msg[{}]", e.getMessage());
            return ResponseDTO.wrap(500, "/generalTree/editBuild 编辑构建树失败");
        }
    }

    @Override
    public ResponseDTO delNode(String applyid, String id, General_tree_option treeOption) {
        try {
            this.general_treeService.delNode(applyid, id, treeOption);
            return ResponseDTO.succ();
        } catch (Exception e) {
            log.info("/generalTree/delNode 删除节点失败 msg[{}]", e.getMessage());
            return ResponseDTO.wrap(500, "/generalTree/delNode 删除节点失败");
        }
    }

    @Override
    public ResponseDTO saveNode(String applyid, General_tree_option treeOption) {
        try {
            this.general_treeService.saveNode(applyid, treeOption);
            return ResponseDTO.succ();
        } catch (Exception e) {
            log.info("/generalTree/saveNode 保存节点失败 msg[{}]", e.getMessage());
            return ResponseDTO.wrap(500, "/generalTree/saveNode 保存节点失败");
        }
    }
}
